package com.xiaolei.lib.annotation.translators;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.xiaolei.lib.Activity.IActivity;
import com.xiaolei.lib.Activity.bean.AnnotationWrape;
import com.xiaolei.lib.annotation.AutoWrite;
import com.xiaolei.lib.core.ITranslator;

/**
 * 自动注入的注解解释器
 * @author xiaolei
 */
public class AutoWriteTranslator implements ITranslator
{
	@Override
	public void execute(Field field, IActivity activity, AnnotationWrape annotation)
	{
		Class<?> class1 = annotation.get(AutoWrite.class).value();
		Object result = null;
		if(class1 == Void.class)
		{
			class1 = field.getType();
		}
		try
		{
			result = class1.newInstance();
			if(!field.isAccessible())
				field.setAccessible(true);
			field.set(activity, result);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	@Override
	public void execute(Method method, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void execute(Class<?> type, IActivity activity, AnnotationWrape annotation)
	{
		// TODO Auto-generated method stub
		
	}

}
